#include<bits/stdc++.h>
#define int long long 
using namespace std;
char buf[(1<<21)+5],*p1,*p2;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
int read(){
	int f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return f?-x:x;
}
int n,k,T,ans;
int a[1005];
int w(int x){
	int l=x,r=x,v=a[x];
	int sum=0;
	while(1){
		while(l>1&&a[l-1]<=v)l--;
		while(r<n&&a[r+1]<=v)r++;
		if(l==1&&r==n)return sum+n-1;
		v=min(a[l-1],a[r+1]);
		sum+=k;
//		cout<<l<<" "<<r<<endl;
	}
}
signed main(){
	freopen("summer.in","r",stdin);
	freopen("summer.out","w",stdout);
	n=read(),k=read();
	for(int i=1;i<=n;i++)a[i]=read();
	a[0]=1e9+7;
	a[n+1]=1e9+7;
	T=read();
	while(T--){
		int x,l,r;
		ans=0;
		x=read(),l=read(),r=read();
		swap(a[x],a[x+1]);
		for(int i=l;i<=r;i++)ans=ans+w(i);
		printf("%lld\n",ans);
	}
	return 0;
} 
